package com.cloud.drore.eboss.operation.service.impl;

import com.cloud.drore.eboos.common.base.BaseServiceImpl;
import com.cloud.drore.eboos.common.base.MyMapper;
import com.cloud.drore.eboos.common.base.ResultMessage;
import com.cloud.drore.eboss.operation.entity.po.ProductToDistributorSettingPo;
import com.cloud.drore.eboss.operation.entity.po.SaveRelationListPo;
import com.cloud.drore.eboss.operation.mapper.DistributorMapper;
import com.cloud.drore.eboss.operation.mapper.ProductToDistributorSettingMapper;
import com.cloud.drore.eboss.operation.service.IProductToDistributorSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: 根据门票信息获取分销商列表<br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/2/1 20:49 <br>
 * @Author: <a href="1451173193@qq.com">杨亮</a>
 */
@Service
public class ProductToDistributorSettingServiceImpl extends BaseServiceImpl implements IProductToDistributorSettingService {
    @Autowired
    DistributorMapper distributorMapper;
    @Autowired
    ProductToDistributorSettingMapper productToDistributorSettingMapper;

    @Override
    public MyMapper getMapper() {
        return distributorMapper;
    }

    /**
     * @param po
     * @ClassName: ProductToDistributorSettingServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription:根据门票信息获取分销商列表
     * @CreateDate: Created in 2018/2/2 9:12
     * @Author: <a href="1451173193@qq.com">杨亮</a>
     * @Modify:
     */
    @Override
    public ResultMessage getDistributorListByTicket(Long id) {
        return new ResultMessage(distributorMapper.getDistributorListByTicket(id));
    }

    /**
     * @param po
     * @ClassName: ProductToDistributorSettingServiceImpl
     * @Return: com.cloud.drore.eboos.common.base.ResultMessage
     * @Decription: 列表保存操作
     * @CreateDate: Created in 2018/2/5 15:51
     * @Author: <a href="1451173193@qq.com">杨亮</a>
     * @Modify:
     */
    @Override
    @Transactional
    public ResultMessage saveProductRelationList(SaveRelationListPo po) {

        //更新的列表
        List<ProductToDistributorSettingPo> updateList = po.getUpdateList();
        if (updateList != null && updateList.size() > 0) {
            updateList.stream().forEach(item -> productToDistributorSettingMapper.updateProductRelation(item));
        }

        return new ResultMessage();
    }
}
